package wetalk.software.bupt.com.wetalk.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.util.Log;
import android.view.KeyEvent;
import android.view.WindowManager;
import android.widget.TextView;

import wetalk.software.bupt.com.wetalk.R;
import wetalk.software.bupt.com.wetalk.application.MyApplication;


/**
 * 自定义透明的dialog
 */
public class CustomDialog extends Dialog{
    private static final String Tag="XIAOMA?CustomDialog";

    private static String mContent;
    private static CustomDialog dialog;
    private static boolean flag=false;

    private CustomDialog(Context context,String content) {
        super(context, R.style.CustomDialog);
        mContent=content;
        initView();

    }



    public static CustomDialog getDialog(Context context,String content){
        if(flag==false){
            dialog=new CustomDialog(context,content);
            flag=true;
        }

        return dialog;
    }



    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode){
            case KeyEvent.KEYCODE_BACK:
                if(CustomDialog.this.isShowing())
                    CustomDialog.this.dismiss();
                break;
        }
        return true;
    }

    private void initView(){
        setContentView(R.layout.dialog_view);
        ((TextView)findViewById(R.id.tvcontent)).setText(mContent);
        setCanceledOnTouchOutside(true);
        WindowManager.LayoutParams attributes = getWindow().getAttributes();
        attributes.alpha=0.9f;
        getWindow().setAttributes(attributes);
        setCancelable(false);

    }

    public void close(){
        if(this.isShowing()){
            this.dismiss();
        }
        flag=false;

    }

    public void setContent(String content) {
        mContent = content;
    }
}